/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.coraci.anag.test;


import it.coraci.anag.db.mongo.controllers.MongoDocumentJpaController;
import it.coraci.anag.db.mongo.entities.Attribute;
import it.coraci.anag.db.mongo.entities.MongoDocument;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Persistence;
import javax.swing.JOptionPane;

/**
 *
 * @author Luca
 */
public class BasicTester {

    public static void main(String[] args) {
        System.out.println("[tester]");
        
//        MongoDBConfigurationManager.getInstance();
        
        MongoDocumentJpaController cc = new MongoDocumentJpaController(Persistence.createEntityManagerFactory("nosqlDBPU"));
        MongoDocument doc = new MongoDocument();
        doc.setNotes("stranezza");
        List<Attribute> values = new ArrayList<Attribute>();
//        Map<String, Attribute> valori = new HashMap<>();
        values.add(new Attribute("scadenza", "domani"));
        values.add(new Attribute("colore", "rosso"));
        doc.setValues(values);
        cc.create(doc);
        
        JOptionPane.showMessageDialog(null, "DOCUMENTO CREATO");
        MongoDocument findMongoDocument = cc.findMongoDocument(doc.getId());
        List<Attribute> vvv = findMongoDocument.getValues();
        for (Attribute aa : vvv) {
            System.out.println("KEY: "+aa.getKey()+" , VALUE: "+aa.getValue());
            aa.setValue("CAMBIATO");
        }
        JOptionPane.showMessageDialog(null, "DOCUMENTO CAMBIATO");
        try {
            cc.edit(findMongoDocument);
            System.out.println("UPDATE DONE");
        } catch (Exception ex) {
            Logger.getLogger(BasicTester.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
//        mDoc.setPath("C:\\file\\dei\\sogni");
//        Map<String,String> keyValues = new HashMap<String,String>();
//        keyValues.put("scadenza", "17/08/2018");
//        keyValues.put("emesso", "10/11/2002");
//        keyValues.put("Comune", "Perugia");
        
//        mDoc.setParams(keyValues);
//        cc.create(mDoc);
        System.out.println("CREATO !!");
                
        
        

//        IDDocType dDocType = new IDDocType();
//        dDocType.setType("Patente");
//        List<String> params = new ArrayList<String>();
//        params.add("Scadenza");
//        params.add("Emessa il");
//        dDocType.setParams(params);
//
//        IDDocTypeJpaController dDocTypeJpaController = new IDDocTypeJpaController(Persistence.createEntityManagerFactory("dbAnagBasePU"));
//        dDocTypeJpaController.create(dDocType);
//        
//        IDDocument dDocument = new IDDocument();
//        dDocument.setType(dDocType);
//        System.out.println("Type created OK");
//        
//        IDDocumentJpaController dDocJpaController = new IDDocumentJpaController(Persistence.createEntityManagerFactory("dbAnagBasePU"));
//        dDocJpaController.create(dDocument);
//        System.out.println("ID-Document created OK");
//        
//        Person p = new Person();
//        p.setNome("Luca");
//        p.setCognome("Coraci");
//        List<IDDocument> docs = new ArrayList<>();
//        docs.add(dDocument);
//        p.setIddocuments(docs);
//        
//        PersonJpaController pc = new PersonJpaController(Persistence.createEntityManagerFactory("dbAnagBasePU"));
//        pc.create(p);
//        System.out.println("Person"
//                + ""
//                + ""
//                + " created OK");
//        
        
    }

}
